﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WatchSMSXML.Settings
{
    public static class AppSettings
    {
        public static int TimeoutMins
        {
            get
            {
                return GetAppSetting("TimeoutMins", 3);
            }
        }
        public static string WatchFolder
        {
            get {
                return GetAppSetting("WatchFolder", "");
            }
        }
        public static string WatchFilter
        {
            get {
                return GetAppSetting("WatchFilter", "");
            }
        }
        public static string MySQLDB
        {
            get
            {
                return GetAppSetting("MySQLDB", "");
            }
        }
        public static string MySQLDBPort
        {
            get
            {
                return GetAppSetting("MySQLDBPort", "");
            }
        }
        public static string MySQLDatabase
        {
            get
            {
                return GetAppSetting("MySQLDatabase", "");
            }
        }
        public static string MySQLUser
        {
            get
            {
                return GetAppSetting("MySQLUser", "");
            }
        }
        public static string MySQLPassword
        {
            get
            {
                return GetAppSetting("MySQLPassword", "");
            }
        }
        private static T GetAppSetting<T>(string appKey, T valueIfMissing)
        {
			string appSettingvalue = GetAppSettingViaKey(appKey);

            if (string.IsNullOrEmpty(appSettingvalue)) return valueIfMissing;

            T toReturn = (T)Convert.ChangeType(appSettingvalue, typeof(T));

            return toReturn;
        }
        private static string GetAppSettingViaKey(string appKey)
        {
            return System.Configuration.ConfigurationManager.AppSettings[appKey];
        }
    }
}